<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>案例6</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style-type: none;
            text-decoration: none;
        }
        
        #fade {
            width: 500px;
            height: 300px;
            margin: 0 auto;
            position: relative;
        }
        
        ul {
            width: 326px;
            height: 50px;
            margin: 0 auto;
        }
        
        ul li {
            margin: 10px;
            list-style: none;
            display: block;
            width: 40px;
            height: 30px;
            border-radius: 50%;
            float: left;
            background-color: darksalmon;
            line-height: 30px;
            text-align: center;
        }
        
        a {
            color: white;
            text-decoration: none;
            font-size: larger;
        }
    </style>
</head>

<body>

    <div id="fade">
        <img src="./res06 (1)/res06/01.jpg" width="500px" height="300px" id="lunbo">
        <ul>
            <li><a href="#">1</a></li>
            <li><a href="#">2</a></li>
            <li><a href="#">3</a></li>
            <li><a href="#">4</a></li>
            <li><a href="#">5</a></li>
        </ul>
        <script>
            var lb = document.getElementById("lunbo")
            var num = 1;
            // 自动换图（定时器）
            setInterval(function() {
                num++;
                if (num == 6) {
                    num = 1;
                }
                lb.src = "./res06 (1)/res06/0" + num + ".jpg"

            }, 3000)
            var left = document.getElementById("left")
            var right = document.getElementById("right")
                // 按钮事件
            var allLi = document.getElementsByTagName("li");
            for (var i = 0; i < allLi.length; i++) {
                console.log(allLi[i].index);
                // 给每个li元素赋值，每循环一次，i+1;
                allLi[i].index = i; //索引赋值
                allLi[i].onclick = function() {
                    // li的索引是从0开始的，所以要+1
                    var num = this.index + 1;
                    lb.src = "./res06 (1)/res06/0" + num + ".jpg"
                }
            }
        </script>
</body>
<ml>